package org.autoparser.exttree;

import java.io.File;
import java.util.LinkedList;
import java.util.Queue;

import org.autoparser.exttree.termoper.ZExtractTerms;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ZExtTree extends ZExtTreeNode{
	public void setDataContainer(ZDataContainer datac){
		Queue<ZExtTreeNode> broadQueue = new LinkedList<ZExtTreeNode>();
		if(this.getChilds() != null)
			broadQueue.addAll(this.getChilds());
		while(!broadQueue.isEmpty()){
			ZExtTreeNode treeNode = broadQueue.poll();
			ZExtractTerms tmpTerms = treeNode.getExtterms();
			if(tmpTerms != null){
				tmpTerms.setDataMap(datac.getSubContainer(tmpTerms.getKey()));
			}
			broadQueue.addAll(treeNode.getChilds());
		}
	}
	public ZExtTree(File xmlFile) throws DocumentException{
		super();
		SAXReader reader = new SAXReader();
		Document doc = reader.read(xmlFile);
		Element elem = doc.getRootElement();
		super.init(elem);
	}
}
